﻿/*****************************************************************************
 
 Use of Ext is under the Ext JS license, for more information, 
 please visit http://extjs.com/products/license.php page. 
  
 You should confirm that you have read, understood and accept ethical criteria listed. 
 If not, see <http://www.mvcnext.com/license/>.
  
 Version: 1.0.0.0
 Website: http://www.mvcnext.com/
 
 Copyright (c) Yoganand R. All rights reserved.
 For continued development and updates, visit http://yogsbreath.net
 
 ******************************************************************************/
using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Web.UI;
using System.Text;

namespace MVCnExt.Web.UI.Ext
{
    [ToolboxData("<{0}:ExtStore />")]
    public class ExtGroupingStore : ExtStore
    {
        private List<ScriptReference> _references = new List<ScriptReference>();

        private List<SortInfo> _sortInfo = new List<SortInfo>();

        public override IList<ScriptDescriptor> GetScriptDescriptors()
        {
            IList<ScriptDescriptor> list = base.GetScriptDescriptors();

            if (list.Count == 0)
                list.Add(new ExtScriptControlDescriptor("Ext.data.Store", "ctl00"));

            ScriptControlDescriptorBase desc = (ScriptControlDescriptorBase)list[0];

            desc.Type = "Ext.data.GroupingStore";

            String[] properties = new String[]{
                
            };

            Type component = typeof(ExtGroupingStore);

            foreach (String property in properties)
            {
                PropertyInfo i = component.GetProperty(property);

                if (i == null)
                    throw new InvalidOperationException(String.Format("Property not found, 'ExtGroupingStore.{0}'", property));

                Object value = i.GetValue(this, null);

                if (value == null)
                {
                    continue;
                }

                if (!(value is String))
                    desc.AddPropertyBase(property, value);
                else
                    desc.AddPropertyBase(property, String.Format("'{0}'", value));
            }

            //add selection model
            if (!string.IsNullOrEmpty(data.Description.ToString()))
            {
                desc.AddPropertyBase("data", data.Description.ToString().Trim().Replace(Environment.NewLine, ""));
            }

            return list;
        }

        #region Public Properties

        /// <summary>
        /// An array of field definition objects, or field name strings.
        /// </summary>                      
        [Description("An array of field definition objects, or field name strings.")]
        [Bindable(true)]
        [DefaultValue("")]
        [Localizable(true)]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        public ExtData data { get; set; }


        #endregion
    }
}
